package com.etc.controller;

import com.etc.entity.FxMusic;
import com.etc.service.FxMusicService;
import com.etc.util.ResponseData;
import com.github.pagehelper.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin("*")
//@Api(value = "歌曲控制器")
public class FxMusicController {

    @Autowired
    private FxMusicService service;

//    @ApiOperation(value = "按id查询歌曲" ,httpMethod = "GET" , notes = "按id查询歌曲",response = FxMusic.class)
//    还待封装
    @GetMapping("music/{id}")
    public FxMusic selectByID( @PathVariable("id") int id){
        FxMusic fxMusic = service.selectByPrimaryKey(id);
        return fxMusic;
    }

    //还待封装
    @GetMapping("music/")
    public Page<FxMusic> selectByPage(@RequestParam(value = "keywords",defaultValue = "",required = false) String keywords,@RequestParam(value = "page" , defaultValue = "1" ,required = false) int page ,@RequestParam(value = "limit",defaultValue = "10",required = false) int limit){
        Page<FxMusic> fxMusics = service.selectByPage(keywords, page, limit);
        return fxMusics;
    }
    @GetMapping("music/page/")
    public ResponseData selectByPage2(@RequestParam(value = "keywords",defaultValue = "",required = false) String keywords, @RequestParam(value = "page" , defaultValue = "1" ,required = false) int page , @RequestParam(value = "limit",defaultValue = "10",required = false) int limit){
        Page<FxMusic> fxMusics = service.selectByPage(keywords, page, limit);
        ResponseData responseData = new ResponseData();
        responseData.setData(fxMusics.getResult());
        return responseData;
    }
    @GetMapping("/music_userid")
    public Page<FxMusic> selectByuserid(@RequestParam(value = "pageNo" , defaultValue = "1" ,required = false) int pageNo ,@RequestParam(value = "pageSize",defaultValue = "10",required = false) int pageSize,@RequestParam(value = "userid") Integer userid){
        Page<FxMusic> fxMusics = service.selectByUserid( pageNo, pageSize,userid);
        return fxMusics;
    }

    //还待封装
    @DeleteMapping("music/{id}")
    public boolean delete(@PathVariable("id") int id) {
        boolean b = service.deleteByPrimaryKey(id);
        return b;
    }

    //还待封装
    @PutMapping("music/")
    public boolean update(@RequestBody FxMusic music){
        boolean b = service.updateByPrimaryKeySelective(music);
        return b;
    }


}